package com.liufh;

import com.liufh.demo.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

/**
 * @author: liufh
 * @create: 2021-12-30 16:35
 */
public class DubboConsumerMain {

    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        System.out.println("服务消费者启动成功...");
        ConsumerComponent component = context.getBean(ConsumerComponent.class);
        while (true) {
            System.in.read();
            try {
                String hello = component.sayHello("mm");
                System.out.println("result :" + hello);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 说明：
     * 此处 组件扫描@ComponentScan用的是spring的，所以@Component也是spring的
     * 注意和provider的区分开
     *
     * 通过@EnableDubbo完成dubbo配置，使用dubbo功能
     */
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan("com.liufh")
    @EnableDubbo
    static class ConsumerConfiguration {
    }

}
